package kr.co.mcshop.optionDetail;

import java.util.List;
import java.util.Map;

import kr.co.mcshop.option.OptionService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping(value="/admin")
@Controller
public class OptionDetailController {
	
	@Autowired
	OptionDetailService DetailService;
	
	@Autowired
	OptionService optionService;
	
	@RequestMapping(value="/OptionDetailListForm")
	public String OptionDetailList(@RequestParam Map map,Model model){
		System.out.println(map.get("no"));
		String no = (String) map.get("no");
		List OptionList = optionService.getAllOption(map);
		List OptionDetailList = DetailService.getAllOptionDetail(Integer.parseInt(no));
		System.out.println(OptionList);
		System.out.println(OptionDetailList);
		model.addAttribute("OptionList", OptionList);
		model.addAttribute("OptionDetailList", OptionDetailList);
		return "admin/option/OptionDetailListForm";	
	}
	
	@RequestMapping(value="/OptionDetailInsertForm")
	public String OptionDetailInsertForm(@RequestParam Map map,Model model){
		model.addAttribute("OptionList", map);
		return "admin/option/OptionDetailInsertForm";	
	}
	
	@RequestMapping(value="/OptionDetailInsert")
	public String OptionDetailInsert(@RequestParam Map map,Model model){
		DetailService.InsertOptionDetail(map);
		model.addAttribute("no", (Integer.parseInt((String) map.get("board_no"))));
		return "redirect:/admin/OptionDetailListForm";
	}
	
	@RequestMapping(value="/OptionDetailEditForm")
	public String OptionDetailEditForm(@RequestParam Map map, Model model){
		model.addAttribute("no", map.get("no"));
		model.addAttribute("board_no", map.get("board_no"));
		return "admin/option/OptionDetailEditForm";
	}
	
	@RequestMapping(value="/OptionDetailEdit")
	public String OptionDetailEdit(@RequestParam Map map, Model model){
		DetailService.UpdateOptionDetail(map);
		model.addAttribute("no", (Integer.parseInt((String) map.get("board_no"))));
		return "redirect:/admin/OptionDetailListForm";
	}
	
	@RequestMapping(value="/OptionDetailDelete")
	public String OptionDetailDelete(@RequestParam Map map, Model model){
		DetailService.DeleteOptionDetail(map);
		model.addAttribute("no", (Integer.parseInt((String) map.get("board_no"))));
		return "redirect:/admin/OptionDetailListForm";
	}
}
